<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2021-12-31 09:48:04
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-05-06 16:47:49
-->
<template>
  <div class="app-container">
    <div class="header">
      <div class="bread" @click="zxChi" :class="active == 1 ? 'active' : ''">
        <p>证书代管</p>
      </div>
      <div
        class="bread"
        style="margin-left: 20px"
        @click="tcChi"
        :class="active == 2 ? 'active' : ''"
      >
        <p>托管订单</p>
      </div>
      <div class="search">
        <el-input
          v-model="input"
          placeholder="请输入资质名称"
          clearable
        ></el-input>
        <el-button type="primary" size="default" @click="search"
          >搜索</el-button
        >
      </div>
      <div class="btn"></div>
    </div>
    <div class="chooise">
      <div class="left">
        <span>场景：</span>
        <el-select
          v-model="value"
          ref="sel"
          clearable
          @visible-change="(v) => visibleChange(v, 'sel', selClick, admClick)"
          class="sel-sence"
          @change="querySceneList"
        >
          <el-option
            v-for="item in sceneOptions"
            :key="item.sceneId"
            :label="item.name"
            :value="item.sceneId"
          >
          </el-option>
        </el-select>
        <el-button
          type="primary"
          icon="iconfont icon-shaixuan"
          size="default"
          @click="screen"
        >
          高级筛选
        </el-button>
      </div>
      <div class="right" v-if="chioose == false">
        <el-button type="primary" size="default" @click="setPrice"
          >设置价格</el-button
        >
      </div>
    </div>
    <div v-if="scenArr !== []" class="scenF">
      <div v-for="(item, index) in scenArr" :key="index" class="scenF-content">
        <div class="scenF-detail" @click="scenSearch(item.sceneId)">
          {{ item.sceneList }}
          <i
            class="el-icon-circle-close"
            @click.stop="scenDel(index)"
            style="margin-left: 10px"
          ></i>
        </div>
      </div>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      ref="multipleTable"
      @selection-change="handleSelectionChange"
      :height="tableHight"
      v-if="chioose"
    >
      <template slot="empty" class="emptyBg">
        <img src="@/assets/images/empty.jpg" alt="" />
      </template>
      <el-table-column type="selection"></el-table-column>
      <el-table-column label="证书名称" align="center" prop="certTypeId">
        <template slot-scope="scope">
          {{ scope.row.certType.certName }}
        </template>
      </el-table-column>
      <el-table-column label="持有人" align="center" prop="belongerName" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="证书主图" align="center" prop="remark">
        <template slot-scope="scope">
          <el-image
            style="height: 100%"
            :src="scope.row.remark"
            :preview-src-list="[scope.row.remark]"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column
        label="有效期"
        align="center"
        prop="certValidity"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.foreverValidity == "Y"
              ? "永久有效"
              : parseTime(scope.row.certValidity, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="certNumber">
        <template slot-scope="scope">
          {{
            scope.row.foreverValidity == "Y"
              ? "正常"
              : compareDate(scope.row.certValidity)
              ? "正常"
              : "已过期"
          }}
        </template>
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column
        label="托管时间"
        align="center"
        prop="trusteeshipTime"
        width="180"
      />
    </el-table>
    <div v-else>
      <el-table
        :data="tableData"
        style="width: 100%"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
        :height="tableHight"
      >
        <template slot="empty" class="emptyBg">
          <img src="@/assets/images/empty.jpg" alt="" />
        </template>
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="订单编号" align="center" prop="orderNumber">
        </el-table-column>
        <el-table-column label="公司名称" align="center" prop="companyName" />
        <el-table-column label="手机号码" align="center" prop="phone" />
        <el-table-column
          label="套餐"
          align="center"
          prop="numberPackage"
          width="180"
        >
          <template slot-scope="scope">
            {{ scope.row.numberPackage }}/{{ scope.row.timePackage }}年
          </template>
        </el-table-column>
        <el-table-column label="金额" align="center" prop="amount" width="180">
        </el-table-column>

        <el-table-column label="支付方式" align="center" prop="payType">
          <template slot-scope="scope">
            {{ scope.row.payType == "1" ? "微信" : "支付宝" }}
          </template>
        </el-table-column>
        <el-table-column label="下单时间" align="center" prop="orderTime" />
        <el-table-column label="支付时间" align="center" prop="payTime" />
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            {{ scope.row.status == 1 ? "已支付" : "未支付" }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      prev-text="上一页"
      next-text="下一页"
      background
      :page-sizes="[10, 20, 30, 40, 50, 100]"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-size="pageSize"
      layout=" ->,total,sizes, prev, pager, next, jumper "
      :total="total"
    >
    </el-pagination>
    <set-price :dialog="dialog"></set-price>
    <manage-screen
      :dialog="dialog"
      :switchShow="switchShow"
      v-if="dialog.screenEcejt"
      :type="type"
      @sceneArr="sceneArr"
    ></manage-screen>
    <drag-table
      :dialog="dialog"
      :type="type"
      v-if="dialog.senceAdminEject"
      ref="dragTable"
    ></drag-table>
  </div>
</template>

<script>
import { trusteeshipList, trusteeshipVipList } from "@/api/cert/certDeposit";
import setPrice from "./conponents/setPrice.vue";
import ManageScreen from "./conponents/manageScreen.vue";
import DragTable from "./conponents/dragTable.vue";
import { queryScene } from "@/api/currency";
export default {
  components: { setPrice, ManageScreen, DragTable },
  data() {
    return {
      tableHight: window.innerHeight - 330,
      type: 34,
      active: 1,
      chioose: true,
      pageNum: 1,
      pageSize: 10,
      total: 0,
      input: "",
      value: "",
      selShow: true,
      tableData: [],
      scenArr: [],
      sceneOptions: [],
      multipleSelection: [],
      switchShow: [
        {
          label: "证书名称",
          stage: "certTypeId",
        },
        {
          label: "持有人",
          stage: "belongerName",
        },
        {
          label: "身份证号",
          stage: "idCard",
        },
        {
          label: "手机号",
          stage: "phone",
        },
        {
          label: "公司名称",
          stage: "companyName",
        },
        {
          label: "有效期",
          stage: "certValidity",
        },
        {
          label: "托管时间",
          stage: "trusteeshipTime",
        },
      ],
      dialog: {
        setShow: false,
        screenEcejt: false,
        dialogTableVisible: false,
        dialogScreenVisible: false,
        dialogPerCha: false,
        dialogEnter: false,
        senceAdmin: false, //场景管理
        senceAdminEject: false,
        distributionShow: false,
        distributionShowEject: false,
      },
    };
  },
  created() {
    this.getList();
    this.getScene();
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        this.tableHight = window.innerHeight - 330;
      })();
    };
  },
  activated() {
    this.tableHight = window.innerHeight - 330;
  },
  methods: {
    zxChi() {
      this.scenArr = [];
      this.type = 34;
      this.chioose = true;
      this.active = 1;
      this.pageNum = 1;
      this.value = "";
      this.input = "";
      this.tableData = [];
      this.switchShow = [
        {
          label: "证书名称",
          stage: "certTypeId",
        },
        {
          label: "持有人",
          stage: "belongerName",
        },
        {
          label: "身份证号",
          stage: "idCard",
        },
        {
          label: "手机号",
          stage: "phone",
        },
        {
          label: "公司名称",
          stage: "companyName",
        },
        {
          label: "有效期",
          stage: "certValidity",
        },
        {
          label: "托管时间",
          stage: "trusteeshipTime",
        },
      ];
      this.getList();
      this.getScene();
    },
    tcChi() {
      this.scenArr = [];
      this.type = 37;
      this.chioose = false;
      this.active = 2;
      this.value = "";
      this.input = "";
      this.pageNum = 1;
      this.tableData = [];
      this.switchShow = [
        {
          label: "订单编号",
          stage: "orderNumber",
        },
        {
          label: "公司名称",
          stage: "companyName",
        },
        {
          label: "手机号码",
          stage: "phone",
        },
        {
          label: "金额",
          stage: "amount",
        },
        {
          label: "支付方式",
          stage: "payType",
        },
        {
          label: "状态",
          stage: "status",
        },
        {
          label: "支付时间",
          stage: "payTime",
        },
        {
          label: "下单时间",
          stage: "orderTime",
        },
      ];
      this.getVipList();
      this.getScene();
    },
    getVipList(val) {
      trusteeshipVipList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        sceneId: val,
        identification: this.input,
        type: 3,
      }).then((res) => {
        this.tableData = res.rows;
        console.log(res.rows);
        this.total = res.total;
      });
    },
    //   设置价格
    setPrice() {
      this.dialog.setShow = true;
    },
    // 新建资质
    newQua() {
      this.dialog.newQuaShow = true;
    },
    // 请求场景
    getScene() {
      queryScene({
        type: this.type,
      }).then((res) => {
        if (res.default !== null) {
          res.scenes.unshift(res.default);
          this.sceneOptions = res.scenes;
        } else {
          this.sceneOptions = res.scenes;
        }
      });
    },
    // 打开高级筛选
    screen() {
      this.dialog.screenEcejt = true;
      this.$nextTick(function () {
        this.dialog.dialogScreenVisible = true;
      });
    },
    // 点击临时搜索
    scenSearch(id) {
      if (this.type == 34) {
        this.getList(id);
      } else if (this.type == 37) {
        this.getVipList(id);
      }
    },
    // 删除临时搜索
    scenDel(i) {
      this.scenArr.splice(i, 1);
      if (this.scenArr.length == 0) {
        if (this.type == 34) {
          this.getList();
        } else if (this.type == 37) {
          this.getVipList();
        }
      }
    },
    // 获取数组
    sceneArr(data) {
      this.scenArr.push(data);
    },
    querySceneList() {
      this.getList(this.value);
    },
    //管理
    admClick() {
      this.dialog.senceAdminEject = true;
      this.$nextTick(function () {
        this.dialog.senceAdmin = true;
      });
    },
    //新建场景
    selClick() {
      this.screen();
    },
    // 场景下拉框按钮
    visibleChange(visible, refName, onClick, onClick2) {
      if (visible) {
        const ref = this.$refs[refName];
        let popper = ref.$refs.popper;
        if (popper.$el) popper = popper.$el;
        if (
          !Array.from(popper.children).some(
            (v) => v.className === "el-cascader-menu__list"
          )
        ) {
          const el = document.createElement("ul");
          el.className = "el-cascader-menu__list";
          el.style =
            "border-top: solid 1px #E4E7ED; padding:0; color: #606266;";
          el.innerHTML = `<li class="el-cascader-node" >
                            <span class="el-cascader-node__label" style='color:#1267FA'>新建场景</span>
                            </li>
                        `;
          const el2 = document.createElement("ul");
          el2.className = "el-cascader-menu__list";
          el2.innerHTML = `<li class="el-cascader-node" >
                            <span class="el-cascader-node__label" style='color:#1267FA'>管理</span>
                            </li>
                        `;
          popper.appendChild(el);
          popper.appendChild(el2);
          el2.onclick = () => {
            onClick2 && onClick2();
            if (ref.toggleDropDownVisible) {
              ref.toggleDropDownVisible(false);
            } else {
              ref.visible = false;
            }
          };
          el.onclick = () => {
            // 底部按钮的点击事件 点击后想触发的逻辑也可以直接写在这
            onClick && onClick();
            // 以下代码实现点击后弹层隐藏 不需要可以删掉
            if (ref.toggleDropDownVisible) {
              ref.toggleDropDownVisible(false);
            } else {
              ref.visible = false;
            }
          };
        }
      }
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.pageNum = 1;
      this.getList();
    },
    // 分页器
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getList();
    },
    search() {
      this.getList();
    },
    // 获取表格数据
    getList(val) {
      trusteeshipList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        sceneId: val,
        identification: this.input,
      }).then((res) => {
        this.tableData = res.rows;
      });
    },
    // 表格前多选器
    handleSelectionChange(val) {
      this.multipleSelection = val;
      if (val.length == 0) {
        this.selShow = true;
      }
      if (val.length > 1) {
        this.disabled = true;
      } else {
        this.disabled = false;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  height: 74px;
  display: flex;
  border-bottom: 1px solid #ececec;
  .bread {
    display: flex;
    align-items: center;
    margin-left: 5px;
    padding: 0 10px;
    height: 30px;
    display: flex;
    vertical-align: middle;
    height: 74px;
    img {
      height: 100%;
    }
    i {
      font-size: 30px;
    }
    p {
      text-align: center;
      //   margin-left: 10px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      //   color: #2b2b2b;
    }
  }
  .search {
    display: flex;
    height: 34px;
    margin: auto;
  }
}
.chooise {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  .sel {
    margin: 0 14px;
  }
  .sel-sence {
    margin-right: 20px;
  }
  .el-button {
    font-size: 14px;
    /deep/ span {
      margin-left: 5px;
    }
  }
}
.el-pagination {
  margin-top: 24px;
  /deep/ .el-pagination__total {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    margin-right: 25px;
  }
  /deep/ .btn-prev {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .btn-next {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .number {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-input__inner {
    // width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .more {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-pagination__jump {
    .el-input__inner {
      width: 40px;
      height: 40px;
    }
  }
}
.sel {
  margin-top: 20px;
  span {
    margin-right: 40px;
  }
}
.scenF {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  .scenF-content {
    display: flex;
    margin-left: 10px;
    margin-top: 10px;
    .scenF-detail {
      height: 36px;
      line-height: 36px;
      padding-left: 20px;
      padding-right: 20px;
      border: 1px solid #9aa1af;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #666666;
      .el-icon-circle-close {
        transform: translateY(3px);
      }
    }
  }
}
.active {
  color: #1267fa !important;
  height: 74px;
  border-bottom: 2px solid #1267fa;
}
</style>